<template>
  <el-dialog
    title=">强行修改运单状态"
    :modal="false"
    :visible.sync="centerDialogVisible"
    width="50%"
    center
  >
    <div v-if="showdata">
      <el-row :gutter="6">
        <el-form
          ref="paramForm"
          :model="paramData"
          size="mini"
          label-width="280px"
        >
          <el-col :span="14">
            <el-form-item label="现在状态" prop="nowStatus">
              <span>{{ m(statusOptions[paramData.nowStatus]) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item label="修改后状态" prop="status">
              <el-select
                v-model="paramData.status"
                placeholder="请选择状态"
                clearable
                filterable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(k, v) in statusOptions"
                  :key="k"
                  :label="m(statusOptions[v])"
                  :value="parseInt(v)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="centerDialogVisible = false">取 消</el-button>
      <el-button
        type="primary"
        @click="forceUpdateWaybillStatus"
        v-loading.fullscreen.lock="fullscreenLoading"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { m } from "@/store/yg/common/local";

export default {
  props: ["row", "data", "more"],
  data() {
    return {
      fullscreenLoading: false,
      centerDialogVisible: false,
      paramData: {
        id: 0,
        nowStatus: "",
        status: ""
      },
      statusOptions: {},
      showdata: false
    };
  },

  methods: {
    m(k) {
      return m(k);
    },
    initStatusOptions(bean) {
      var uri = "/api/entry/source?bean=" + bean;
      axios.post(constant.API_SERVER + uri).then(
        response => {
          this.statusOptions = response.data;
          delete this.statusOptions[65];
          delete this.statusOptions[105];
          this.showdata = true;
        },
        error => {
          console.info(error);
        }
      );
    },
    //强行修改运单状态
    forceUpdateWaybillStatus() {
      var param = {};
      param["id"] = this.data["id"];
      param["status"] = this.paramData.status;
      console.log("param:", param);
      this.fullscreenLoading = true;
      ajax("forceUpdateWaybillStatus", param).then(
        res => {
          this.fullscreenLoading = false;
          if (res.code != 200) {
            if (null != res.message) {
              this.$message.error(m(res.message));
            } else {
              this.$message.error("修改失败!");
            }
          } else {
            this.$message.success("修改成功!");
            this.centerDialogVisible = false;
          }
        },
        error => {
          console.log(error);
        }
      );
    }
  },
  mounted() {
    this.initStatusOptions("waybillStatusSource");
    this.paramData.nowStatus = this.data["status"];
  }
};
</script>

<style></style>
